package org.example.springbook.config;

import lombok.extern.slf4j.Slf4j;
import org.example.springbook.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-07-18
 * Time: 18:41
 */
@ResponseBody
@Slf4j
@ControllerAdvice
public class ErrorHandler {
    @ExceptionHandler
    public Result excption(NullPointerException e) {
        log.error("发生异常,e1:", e);
        return Result.fail("NullPointerException异常, 请联系管理员");
    }

    @ExceptionHandler
    public Result excption(ArithmeticException e) {
        log.error("发生异常,e2:", e);
        return Result.fail("ArithmeticException 异常");
    }

    @ExceptionHandler
    public Result excption(Exception e) {
        log.error("发生异常,e3:", e);
        return Result.fail("内部错误");
    }

}